﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using _表达式树测试.Helper;
using System.Linq.Expressions;
using _表达式树测试.Models;

namespace _表达式树测试
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            List<choose> c = new List<choose>() { 
                new choose(){ text="--请选择--", value=2},
                new choose(){ text="启用", value=1},
                new choose(){ text="停用", value=0}
            };

            comboBox1.DataSource = c;
            comboBox1.DisplayMember = "text";
            comboBox1.ValueMember = "value";

            using (var db = new Context())
            {
                datagv.DataSource = db.BaseUser.ToList();
                datagv.Columns["Id"].Visible = false;
                datagv.Columns["IP"].Visible = false;
            }
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            string Name = txtName.Text;
            int IsActive = (int)comboBox1.SelectedValue;
            WhereHelper<BaseUser> where = new WhereHelper<BaseUser>();
            where.ContainsExperssion("UserName", Name);
            where.EqualExperssion("IsActive", IsActive);
            using (var db = new Context())
            {
                datagv.DataSource = db.BaseUser.Where(where.GetExperssion()).ToList();
                datagv.Columns["Id"].Visible = false;
                datagv.Columns["IP"].Visible = false;
            }
        }

        public class choose
        {
            public string text { get; set; }
            public int value { get; set; }
        }
    }
}
